$(function () {

    // 设置partner&flag
    // setPartnerInfo();
    // clickAgree();

    $("#mobile").blur(function () {
        var _this = $(this);
        if (!checkPhone()) {
            return false;
        }
        $.post(_this.attr('data-href'), {phone: _this.val()}, success, "json");
        return false;

        function success(data) {
            if (data.code !== 1) {
                showError(_this, data.msg);
            }
        }
    });

    $("#pwd").blur(function () {
        checkPhone();
        checkPwd();
    }).focus(function () {
        showError($(this), errorTxt[7]);
    });

    $("#imgCode").blur(function () {
        checkPhone();
        checkPwd();
        checkImgCode();
    });

    $("#phoneCode").blur(function () {
        checkPhone();
        checkPwd();
        checkImgCode();
        checkPhoneCode();
    });

    $("#exp_phone").blur(function () {
        checkUserPhone();
    });

    $(".userType li").click(function () {
        var typeBox = "#userTypeBox", userType = "#userType", borrow = "#isBorrow", invite = "#inviteBox",
            img1 = "#img1", img2 = "#img2";
        var index = $(this).index();
        $(this).addClass("on").siblings("li").removeClass("on");
        if (index === 1) {
            $("#fenxian").hide();
            $(img1).hide();
            $(img2).show();
            $(typeBox).removeClass("hide").find("input").prop("disabled", false);
            $(invite).hide().find("input").prop("disabled", true);
        } else {
            $("#fenxian").show();
            $(img2).hide();
            $(img1).show();
            $(typeBox).addClass("hide").find("input").prop("disabled", true);
            $(invite).show().find("input").prop("disabled", false);
        }
        $(borrow).val(index === 0 ? 0 : 1);
        $(userType).prop("disabled", index === 1 ? true : false);
    });

    // 发送短信
    $('#sendMsgBtn').click(function () {
        checkPhone();
        checkPwd();
        checkImgCode();
        if (!checkPhone() || !checkPwd() || !checkImgCode()) {
            return false;
        }
        var _this = $(this);
        sendMobileMsgCode(_this.attr('data-href'), $('#mobile').val(), $('#imgCode').val());
    });

    //提交表单
    $("#registerForm").submit(function () {
        checkPhone();
        checkPwd();
        checkImgCode();
        checkPhoneCode();
        if (!(checkPhone() && checkPwd() && checkImgCode() && checkPhoneCode())) {
            return false;
        }

        // var agree = $("#agree").val();
        // if (parseInt(agree) !== 1) {
        //     layer.alert("您还未阅读并同意相关协议", {icon: 0, title: '温馨提醒'});
        //     return false;
        // }

        return ajax_post($(this), 3);
    });

});

// 去掉转义字符、特殊字符
// function clearOther(str) {
//     var str1 = str.replace(/[\'\"\\\/\b\f\n\r\t]/g, '');
//     var str2 = str1.replace(/[\@\+\.\,\!\|\~\`\(\)\#\$\%\^\&\*\{\}\:\;\"\L\<\\\>\?]/g, '');
//     var str3 = str2.replace(/\[|]/g, '');
//     return str3;
// }

// 设置商家信息
// function setPartnerInfo() {
//     var partner = getCookie("partner");
//     var flag = getCookie("flag");
//     var partner2 = partner !== "undefined" ? clearOther(partner) : "";
//     var flag2 = partner !== "undefined" ? clearOther(flag) : "";
//     $("input[name='partner']").val(partner2);
//     $("input[name='flag']").val(flag2);
// }